﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
}

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>采购到货</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.10.3/dist/css/layui.css" rel="stylesheet">
</head>

<body>
    <form class="layui-form" action="" id="baseStoreForm">
        <div class="layui-input-inline">
            <label class="layui-input-inline" style="width:auto">跟单编号</label>
            <div class="layui-input-inline">
                <input type="text" name="document" class="layui-input">
            </div>
            <label class="layui-input-inline" style="width:auto">单据编码</label>
            <div class="layui-input-inline">
                <input type="text" name="documentCode" class="layui-input">
            </div>
            <label class="layui-input-inline" style="width:auto">供应商</label>
            <div class="layui-input-inline">
                <input type="text" name="supplier" class="layui-input">
            </div>

            <label class="layui-input-inline" style="width:auto">物料名称</label>
            <div class="layui-input-inline">
                <input type="text" name="materialName" class="layui-input">
            </div>
            <div class="layui-input-inline">
                <div class="layui-inline">
                    <label class="layui-input-inline" style="width:auto">日期范围</label>
                    <div class="layui-inline" id="ID-laydate-range">
                        <div class="layui-input-inline">
                            <input type="text" autocomplete="off" name="modeDateStart" class="layui-input" id="begindate" placeholder="开始日期">
                        </div>
                        <div class="layui-form-mid">-</div>
                        <div class="layui-input-inline">
                            <input type="text" autocomplete="off" name="modeDateEnd" class="layui-input" id="enddate" placeholder="结束日期">
                        </div>
                    </div>
                </div>
            </div>
            <button class="layui-btn" lay-submit lay-filter="search">查询</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </form>
    <table class="layui-hide" id="ID-table-demo-filter"></table>
    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.10.3/dist/layui.js"></script>
    <script>
        layui.use(['form', 'table', 'laydate'], function () {
            var $ = layui.$;
            var form = layui.form;
            var table = layui.table;
            var laydate = layui.laydate;

            // 初始化日期选择器
            laydate.render({
                elem: '#begindate',
                type: 'date'
            });
            laydate.render({
                elem: '#enddate',
                type: 'date'
            });

            // 渲染表格
            var tableIns = table.render({
                elem: '#ID-table-demo-filter',
                toolbar: 'default',
                height: 315,
                cols: [function () {
                    var arr = [
                        { field: 'purchaseArrivaId', title: '序号', width: 80, fixed: 'left' },
                        { field: 'document', title: '跟单编号', width: 120 },
                        { field: 'documentCode', title: '单据编码' },
                        { field:'purchasingDe', title: '单据状态' },
                        { field: 'supplier', title: '供应商' },
                        { field: 'materialName', title: '物料名称' },
                        { field: 'materialid', title: '物料编码' },
                        { field: 'modeDate', title: '到货数量' },
                        { field: 'modeQuantity', title: '入库数量' },
                        { field: 'documentStatus', title: '单据日期' },
                        { field: 'documentStatus', title: '用料类型' },
                    ];

                    // 初始化筛选状态
                    var local = layui.data('table-filter-test'); // 获取对应的本地记录
                    layui.each(arr, function (index, item) {
                        if (item.field in local) {
                            item.hide = local[item.field];
                        }
                    });
                    return arr;
                }()],
                done: function () {
                    // 记录筛选状态
                    var that = this;
                    that.elem.next().on('mousedown', 'input[lay-filter="LAY_TABLE_TOOL_COLS"]+', function () {
                        var input = $(this).prev()[0];
                        // 此处表名可任意定义
                        layui.data('table-filter-test', {
                            key: input.name,
                            value: input.checked
                        })
                    });
                }
            });

            function loadRoleData() {
                layer.load(2);
                var params = {
                    document: $('[name="document"]').val(),
                    documentCode: $('[name="documentCode"]').val(), // 修正参数名
                    supplier: $('[name="supplier"]').val(),
                    materialName: $('[name="materialName"]').val(),
                    enddate: $('[name="enddate"]').val(),
                    modeDateStart: $('[name="modeDateStart"]').val(),
                    modeDateEnd: $('[name="modeDateEnd"]').val(),
                }

                $.ajax({
                    //url: 'http://localhost:5234/api/PurchaseInvoice/GetPurchaseArrival',
                    url: "@ViewBag.BaseUrl/T7/PurchaseInvoice/GetPurchaseArrival",
                    data: params,
                    type: 'get',
                    dataType: 'json',
                    success: function (res) {
                        console.log(res.data);
                        layer.closeAll('loading');
                        if (res.code === 210) {
                            table.reload('ID-table-demo-filter', { // 修正表格id
                                data: res.data,
                            });
                        }
                        else {
                            layer.msg('获取数据失败: ' + (res.message || '未知错误'), { icon: 2 });
                        }
                    },
                    error: function (xhr, status, error) {
                        layer.closeAll('loading');
                        layer.msg('请求失败: ' + error, { icon: 2 });
                        console.error('Ajax请求失败:', xhr.responseText);
                    }
                });
            }

            // 监听查询按钮提交事件
            form.on('submit(search)', function (data) {
                loadRoleData()
                return false; // 阻止表单跳转
            });
            loadRoleData()
        });
    </script>
</body>

</html>
